import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

// 全局挂载：Vue2 组件可直接 this.$searchAndOpen('keyword')
Vue.prototype.$searchAndOpen = (keyword) => {
  return window.electronSearchAPI && window.electronSearchAPI.searchAndOpen(keyword)
}
// 新增：仅按文件名搜索并打开（支持灵活签名）
Vue.prototype.$searchAndOpenFile = (...args) => {
  return window.electronSearchAPI && window.electronSearchAPI.searchAndOpenFile(...args)
}
// 新增：仅按应用名搜索并打开
Vue.prototype.$searchAndOpenApp = (appname) => {
  return window.electronSearchAPI && window.electronSearchAPI.searchAndOpenApp(appname)
}

// 文件/目录工具：统一挂载为 this.$fileUtil（避免直接操作 fs）
Vue.prototype.$fileUtil = window.electronFileAPI || {
  // 兜底：开发期未注入时给出明确错误
  createFile: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  writeFile: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  readFile: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  deleteFile: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  renameFile: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  createDir: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  deleteDir: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
  readDir: async () => ({ success: false, error: 'electronFileAPI 未注入' }),
}

// 绑定系统模拟 API 到 Vue 原型
Vue.prototype.$simulateMouse = (payload) => {
  if (window.electronSimulateAPI && window.electronSimulateAPI.mouse) {
    return window.electronSimulateAPI.mouse(payload)
  }
  return Promise.resolve({ success: false, error: 'electronSimulateAPI 未注入' })
}

Vue.prototype.$simulateKeyboard = (payload) => {
  if (window.electronSimulateAPI && window.electronSimulateAPI.keyboard) {
    return window.electronSimulateAPI.keyboard(payload)
  }
  return Promise.resolve({ success: false, error: 'electronSimulateAPI 未注入' })
}

Vue.prototype.$simulateScroll = (payload) => {
  if (window.electronSimulateAPI && window.electronSimulateAPI.scroll) {
    return window.electronSimulateAPI.scroll(payload)
  }
  return Promise.resolve({ success: false, error: 'electronSimulateAPI 未注入' })
}



// 绑定截屏 API 到 Vue 原型
Vue.prototype.$captureScreen = () => {
  if (window.electronCaptureAPI && window.electronCaptureAPI.takeScreenshot) {
    return window.electronCaptureAPI.takeScreenshot()
  }
  return Promise.resolve({ success: false, error: 'electronCaptureAPI 未注入' })
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
